[Query]: Adds ability to choose global vs local/focused statistics for FullTextScore#45686
[Query]: Adds ability to choose global vs local/focused statistics for FullTextScore#45686aayush3011 wants to merge 12 commits intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in way to scope BM25 statistics used by FullTextScore in Cosmos DB hybrid search, allowing callers to choose between global container-wide statistics and “local” statistics limited to the query’s target partition ranges.
Changes:
- Added
full_text_score_scopekwarg toquery_items()(sync + async) with validation and docs. - Updated hybrid search aggregators to scope global statistics queries to either all ranges (Global/default) or target ranges (Local).
- Added sync/async test coverage and updated the package changelog.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/azure/cosmos/container.py | Adds full_text_score_scope kwarg, validates values, documents behavior, and passes the option into query feed options. |
| sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py | Async equivalent of full_text_score_scope kwarg support (validation + docs + feed option). |
| sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/hybrid_search_aggregator.py | Uses fullTextScoreScope option to decide whether global statistics queries target all partition ranges or only query target ranges. |
| sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/hybrid_search_aggregator.py | Async equivalent of local vs global partition-range selection for statistics queries. |
| sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search.py | Adds sync tests for Global vs Local scope behavior. |
| sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search_async.py | Adds async tests for Global vs Local scope behavior. |
| sdk/cosmos/azure-cosmos/CHANGELOG.md | Documents the new full_text_score_scope parameter in the unreleased section. |
You can also share your feedback on Copilot code review. Take the survey.
sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search_async.py
Outdated
Show resolved
Hide resolved
simorenoh
left a comment
There was a problem hiding this comment.
Copilot had some comments that may be worthwhile on the tests added - LGTM otherwise
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tvaron3
left a comment
There was a problem hiding this comment.
PR Review — FullTextScore Scope
Clean, well-scoped change. 2 comments (1 recommendation, 1 suggestion).
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Description
Why?
Cosmos DB's implementation of FullTextScore computes BM25 statistics (term frequency, inverse document frequency, and document length) across all documents in the container, including all physical and logical partitions.
While this provides a valid and comprehensive representation of statistics for the entire dataset, it introduces challenges for several common use cases:
This is the Python SDK port of the .NET SDK PR: Azure/azure-cosmos-dotnet-v3#5582
What?
This PR extends the flexibility of BM25 scoring so that developers can choose between:
How?
A new full_text_score_scope keyword argument is added to query_items():
When full_text_score_scope="Local", the hybrid search aggregator uses only the query's target partition ranges (instead of all ranges) when executing the global statistics query. This is a client-side only change, no new HTTP headers are sent to the backend.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines